package com.person.leetcode.editor.cn;

import javax.sound.midi.Soundbank;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
  * 4.寻找两个正序数组的中位数
  * 2022-03-31 15:37:18
**/
public class Sequence_0004_MedianOfTwoSortedArrays {
    public static void main(String[] args) {
        Solution solution = new Sequence_0004_MedianOfTwoSortedArrays().new Solution();
        solution.findMedianSortedArrays(new int[]{1,3},new int[]{2});
    }
    //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public double findMedianSortedArrays(int[] nums1, int[] nums2) {
        //TODO
        List<Integer> arr1 = Arrays.stream(nums1, 0, nums1.length).boxed().collect(Collectors.toList());
        List<Integer> arr2 = Arrays.stream(nums2, 0, nums2.length).boxed().collect(Collectors.toList());
        arr1.addAll(arr2);
        arr1.stream().sorted();
        System.out.println(arr1);
        double res = 0;
        if (arr1.size()%2 == 0){
            res = (arr1.get(arr1.size()/2-1)+arr1.get(arr1.size()/2))/2.0;
        }else{
            res = arr1.get(arr1.size()/2);
        }

        return res;
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}
